﻿using Avalonia.Platform;
using Avalonia.Rendering.SceneGraph;
using Avalonia.Skia;
using Avalonia;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightCAD.Runtime
{
    

    public class DrawingRender : ICustomDrawOperation
    {
        public DrawingRender(DrawingEditorController editor, Rect bounds)
        {
            Editor = editor;
            Bounds = bounds;
        }
        public DrawingEditorController Editor { get; }

        #region ICustomDrawOperation

        public bool Equals(ICustomDrawOperation? other) => false;

        public Rect Bounds { get; }
        public void Dispose()
        {
        }

        public bool HitTest(Point p) => false;

        public void Render(IDrawingContextImpl context)
        {
            var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;
            //if (_parent.IsStopRenderElements)
            //{
            //    _parent.SwapElementCanvs(canvas);
            //    return;
            //}
            DrawCanvas(canvas);
        }
        #endregion

        public void DrawCanvas(SKCanvas canvas)
        {

            //canvas.Clear(VPort.Background);


            ////var wp  = VPort.WorldToScr(new Vector2d(0, 0));
            ////var sp = VPort.ScrToWorld(wp);

            //if (VPort.IsPan)
            //{
            //    VPort.PanViewScope();
            //}

            //VPort.DrawGrid(canvas);
            //VPort.DrawOriginAxis(canvas);
            //if (VPort.IsSelecting)
            //{
            //    VPort.DrawSelectRect(canvas, VPort.PointerPressedPosition, VPort.PointerMovedPosition);
            //}

            //VPort.DrawCounter = DocumentScene.Draw(_parent.doc, canvas);

            //if (DocumentScene.SelectedElements.Count > 0)
            //{
            //    RuntimeScene.DrawElementGrips(canvas);
            //}

            ////if (_parent.CursorType != LcadCursorType.None)
            ////{
            ////    VPort.DrawCursor(canvas, _parent.CursorType);
            ////}

            //if (VPortInputer.IsAuxLineDrawing)
            //{
            //    VPortInputer.AuxLineDraw?.Invoke(canvas, new object[] { VPort.PointerMovedPosition });
            //}

            //if (VPort.IsDragging)
            //{
            //    DocumentScene.DrawDrags(_parent.doc, canvas);
            //}
            //if (VPort.IsDraggingGrip)
            //{
            //    RuntimeScene.DrawDraggingGrip?.Invoke(canvas);
            //}

            //if (VPort.IsPasting)
            //{
            //    DocumentScene.DrawPasteElments(canvas, VPort.PointerMovedPosition);
            //}
        }

    }
}
